<?php
function code62($x) {
    $show = '';
    while($x > 0) {
        $s = $x % 62;
        if ($s > 35) {
            $s = chr($s+61);
        } elseif ($s > 9 && $s <=35) {
            $s = chr($s + 55);
        }
        $show .= $s;
        $x = floor($x/62);
    }
    return $show;
}
function shorturl($url) {
    $url = crc32($url);
    $result = sprintf("%u", $url);
    $shorturl = code62($result);
    //插入数据库等逻辑,方便通过短网址逆差长网址
    return $shorturl;
}
echo shorturl("http://www.baidu.com/api/xxx/aaa");